package org.dromara.rocketmq.demo.producer;

import com.cloud.rocketmq.base.core.CloudMQTemplate;
import com.cloud.rocketmq.base.entity.CloudMQSendResult;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.dromara.rocketmq.demo.listener.TransactionExecutor;
import org.springframework.stereotype.Component;

/**
 * @description:
 * @author: zhou shuai
 * @date: 2022/1/12 17:08
 * @version: v1
 */
@Slf4j
@Component
public class MessageSend {

    @Resource
    private CloudMQTemplate cloudMQTemplate;

    @Resource
    private TransactionExecutor transactionExecutor;


    /**
     * 发送普通消息
     */
    public CloudMQSendResult sendMessage() {
        cloudMQTemplate.syncSend("TP_DTO_TEST_TOPIC", "EC_TEST_DTO", new SendDTO("zhoushuai", 28));
        return CloudMQSendResult.createSuccessResult(null);
    }

    /**
     * 发送事务消息
     */
    public void sendTransactionMessage() {
        final String transactionMessage = "hello consumer i am transaction message!!!";
        CloudMQSendResult cloudMQSendResult = transactionExecutor.sendTransactionMsg(transactionMessage, "messageId");
    }

    /**
     * 消费失败测试
     */
    public void conusmeFailTest() {
        cloudMQTemplate.syncSend("TP_DTO_TEST_TOPIC", "EC_TEST_DTO", "11111122");
    }

}
